from get_proxies_req import get_proxies
from ping import check, sort_by_ping
import asyncio
import click

@click.command()
@click.option(
    "-tg", default=False, help="change uri to tg://. Def: False"
)
def start(tg):
    asyncio.run(main(tg))

async def main(tg):

    print("Start searching..!")

    proxy = []
    [proxy.append(x) for x in get_proxies() if x not in proxy] # Get proxies

    print(f"I found {len(proxy)} proxy!")
    print("Start pinging..!")

    results = await asyncio.gather(*[check(prx) for prx in proxy]) # Get results (proxy/ping)
    await sort_by_ping(results, tg)

if __name__ == "__main__":
    start()


